<?php						
						
include 'db/db_Connect.php';                            
							
$familyResult = mysql_query("SELECT * from Families");
							
while($row = mysql_fetch_array($familyResult)){

	$family_id = $row['family_id'];
	
	$memberResult = mysql_query("SELECT * 
							  FROM FamilyMembers 
							  WHERE family_id = $family_id");
	
	$members = array();
	while($memberRow = mysql_fetch_array($memberResult)){
		array_push($members, $memberRow['first_name']. " ".$memberRow['last_name']);			
	}
	
	$created_by_user_id = $row['created_by_user_id'];
	$creatorResult = mysql_query("SELECT * FROM User WHERE user_id = '$created_by_user_id'");
	$creator = mysql_fetch_array($creatorResult);
	$creatorName = $creator['first_name']." ".$creator['last_name'];
	
	$adoptive_family_user = $row['adoptive_family_user'];
	$adopterResult = mysql_query("SELECT * FROM User WHERE user_id = '$adoptive_family_user'");
	$adopter = mysql_fetch_array($adopterResult);
	$adopterName = $adopter['first_name']." ".$adopter['last_name'];
	
	//<!-- Family ID || Contact 1 Name || Contact 2 Name || Zip || App Date || Created by || Adopted by || Action -->
				echo    "<tr id=\"".$row['family_id']."\"><td>"
							. $row['family_id']
							. "</td><td class=\"center\">"
			                . $members[0]
			                . "</td><td class=\"center\">" 			                
			                . $members[1]              
			                . "</td><td class=\"center\">" 
							. $row['zipcode']
			                . "</td><td class=\"center\">" 
			                . $row['application_date']
			                . "</td><td class=\"center\">"  
			                //. $row['created_by_user_id']
							. $creatorName
							. "</td><td class=\"center\">";
							//. $row['adoptive_family_user']
							
								if ($adoptive_family_user == 0){
								 	echo $adopterName;
								} else{
								 	echo "<a href=\"adopterSummary.php?id=".$adoptive_family_user."\">".$adopterName."</a>";								 		
								}
			                echo "</td><td>" 
 										//. "<a class=\"btn btn-info table-action-EditUser\" >"
 										. "<a class=\"btn btn-info\" href=\"familySummary.php?family_id=" .$row['family_id'] . "\">"
										. "<i class=\"icon-eye-open icon-white\"></i>"  
											." View"                                            
								  . "</a></center>"
							/*	  . " "
								  . "<a class=\"btn btn-danger table-action-deletelink\" id=\"btnDeleteRow\" href=\"#\">"
										. "<i class=\"icon-trash icon-white\"></i>" 
											. "Delete"
								 . "</a></center>" */                  
			                . "</td></tr>";
	
}

include 'db/db_Close.php';			
?>						
